﻿using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Abstractions.Sys;
using JESAI.Application.Abstractions.Sys.Dtos;
using JESAI.Application.Abstractions.Sys.Querys;
using JESAI.AutoMapper.ObjectMapping;
using JESAI.Core.Attributes;
using JESAI.Core.Extensions;
using JESAI.DDD.Dtos;
using JESAI.Platform.Domain.Sys.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JESAI.Application.Service.Sys
{
    [AppService]
    public class OnlineService : IOnlineService
    {
        private readonly IOnlineInfoRepository _onlineInfoRepository;
        private readonly IOnlineFieldRepository _onlineFieldRepository;

        public OnlineService(IOnlineInfoRepository onlineInfoRepository, IOnlineFieldRepository onlineFieldRepository)
        {
            this._onlineInfoRepository = onlineInfoRepository;
            this._onlineFieldRepository = onlineFieldRepository;
        }

        public async Task<PagedDto<OnlineInfoDto>> GetPageList(OnlineInfoPageQuery onlineInfoPageQuery)
        {
            var totalNumber = 0;
            var data = _onlineInfoRepository._DbQueryable
                 .WhereIF(!onlineInfoPageQuery.Name.IsEmpty(), it => it.Name.Contains(onlineInfoPageQuery.Name))
                   .WhereIF(!onlineInfoPageQuery.Code.IsEmpty(), it => it.TableCode.Contains(onlineInfoPageQuery.Code))
                    .ToPageList(onlineInfoPageQuery.PageIndex, onlineInfoPageQuery.PageSize, ref totalNumber);
            return new PagedDto<OnlineInfoDto>(totalNumber, data.MapTo<List<OnlineInfoDto>>());
        }
    }
}
